import Vue from 'vue'
import Vuex from 'vuex'
import server from '@/store/modules/server'
import navigation from "@/store/modules/navigation";

Vue.use(Vuex);
//延迟加载时长
const lazyTime = 1000;
export default new Vuex.Store({
    state: {
        //当前刷新状态
        loading: true,
        //临时刷新
        tempLoading: true
    },
    getters: {
        getLoading(state) {
            return state.loading;
        },
        getTempLoading(state) {
            return state.tempLoading;
        }
    },
    mutations: {
        changeLoading(state, payload) {
            state.loading = payload;
        },
        changeTempLoading(state, payload) {
            state.tempLoading = payload;
        }
    },
    actions: {
        //异步更改加载状态
        asyncChangeLoading({commit, state}, payload) {
            setTimeout(() => {
                commit('changeLoading', payload);
            }, lazyTime);
        }, asyncChangeTempLoading({commit, state}, payload) {
            this.commit('changeTempLoading', true);
            setTimeout(() => {
                commit('changeTempLoading', payload);
            }, lazyTime);
        },
    },
    modules: {
        //服务器数据
        server,
        //导航数据
        navigation
    }
})
